<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>订单详情</title>
	<link rel="stylesheet" href="__PUBLIC__/Product/css/page_orderDetail.css" />
	<script src="__PUBLIC__/Product/js/lib/flexible.js"></script>
</head>

<body style="background-color: #f4f4f4;">
	<div class="orderDetail_box">
		<!--头部-->
		<div class="orderDetail_header">
			<img src="__PUBLIC__/Product/img/fanhui.png" alt="返回" class="goBack">
			<p>订单详情</p>
		</div>
		<!--内容-->
		<div class="orderDetail_content">
			<div class="orderDetail_con_top">
				<p class="orderState"></p>
			</div>
			<div class="logistic">
				<div class="logistic_left">
					<img src="__PUBLIC__/Product/img/car.png" alt="" />
				</div>
				<div class="logistic_con">
					<p class="packageState">点我查看物流</p>
				</div>
				<div class="logistic_right">
					<img src="__PUBLIC__/Product/img/right.png" />
				</div>
			</div>
			<div class="address">
				<div class="address_left">
					<img src="__PUBLIC__/Product/img/address.png" alt="" />
				</div>
				<div class="address_right">
					<p class="address_rt_top">
						收货人：<span class="receiptPerson"></span><span class="telephone"></span>
					</p>
					<p class="address_rt_bot">
						收货地址：<span class="adressDetail"></span>
					</p>
				</div>
			</div>
			<!--订单-->
			<div class="orderDetail_box">
				<div class="orderDetail_num">
					<span>订单编号：</span>
					<span class="orderNum"></span>
					<span class="orderState"></span>
				</div>
				<div class="detailConBox">
					<!-- <div class="orderDetail_con">
						<div class="orderDetail_con_lt">
							<div class="lt_imgBox">
								<img src="" alt="" />
							</div>
						</div>
						<div class="orderDetail_con_rt">
							<p class="p_top">
								<span>话费充值100元，首冲送13兑币</span>
								<span class="red">￥99.80</span>
							</p>
							<p class="p_bot">
								<span>话费已到账，13兑币已到账</span>
								<span class="red">x1</span>
							</p>
						</div>
					</div> -->
				</div>
				<div class="orderDetail_bot">
					<p class="num-money">
						共<span class="num" style="color:#a062e0"></span>件商品，合计：￥<span class="price" style="color:#a062e0"></span>(含运费￥3.0)
					</p>
				</div>
			</div>
			<!--订单号、时间-->
			<div class="orderNum-time">
				<p>订单编号：<span class="orderNum"></span></p>
				<p>创建时间：<span class="createTime"></span></p>
				<p>付款时间：<span class="payTime"></span></p>
				<p>发货时间：<span class="deliverTime"></span></p>
			</div>
		</div>
	</div>
</body>

</html>
<script src="__PUBLIC__/Product/js/lib/jquery3.2.1.js"></script>
<script src="__PUBLIC__/Product/js/lib/transformTime.js"></script>
<script>
	$(function () {
		// 点击返回按钮返回上一页
		$(".goBack").bind("click", function() {
			// window.history.back();location.reload();	//强行刷新
			// window.history.go(-1);  //返回上一页
			window.location.href = document.referrer; //返回上一页并刷新
		});
		var obj = {
			orderStateTop: $('.orderState'), 		// 订单状态顶部的
			logistic: $('.logistic'), 				// 物流信息的整体
			packageState: $('.packageState'), 		// 物流状态
			logisticTime: $('.time'), 				// 物流时间
			receiptPerson: $('.receiptPerson'), 	// 收货人的姓名
			telephone: $('.telephone'), 			// 收货人的电话
			adressDetail: $('.adressDetail'), 		// 收货的详细地址
			orderNumBot: $('.orderNum'), 			// 底部的订单编号
			createTime: $('.createTime'), 			// 订单创建时间
			payTime: $('.payTime'), 				// 订单支付时间
			deliverTime: $('.deliverTime'), 		// 订单发货时间
			orderState: $('.orderState'), 			// 订单详情处的订单状态
			orderNum: $('.orderNum'), 				// 订单详情处的订单编号
			numBot: $('.num-money .num'), 			// 订单详情处的订单数量
			price: $('.num-money .price') 			// 订单详情处的订单总金额
		}
		// 取出商品列表界面传过来的参数  
		function GetRequest() {
			var url = location.search;
			var theRequest = new Object();
			if (url.indexOf("?") != -1) {
				var str = url.substr(1);
				strs = str.split("&");
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
				}
			}
			return theRequest;
		}

		// 进入页面加载订单详情信息
		loadInfo();

		function loadInfo() {
			var orderid = GetRequest().orderid;
			if (orderid.substring(0, 1) == 'J') {
				$.ajax({
					type: 'post',
					url: 'http://a.91jfk.com/Product/Ordershop/OrderDetail',
					data: {
						orderid: orderid
					},
					dataType: 'json',
					success: function (data) {
						console.log(data);
						if (data.code == 1) {
							var res = data.message;
							obj.orderStateTop.text(res.order_state); // 顶部的订单状态
							// 根据订单的状态值判断是否显示物流栏
							if (res.order_state == '待收货' || res.order_state == '已签收') {
								obj.logistic.click(function(){
									var cpy = res.logistics_company;   // 物流公司
            						var num = res.logistics_number;    // 物流单号
            						var callbackUrl = window.location.href;
            						window.location.href = "http://a.91jfk.com/HomePublic/Common/search_express?type=" + cpy + "&postid=" + num + "&callbackurl=" + callbackUrl;
								});
							} else {
								obj.logistic.hide();
							}
							obj.receiptPerson.text(res.receive_name); 		// 收件人姓名
							obj.telephone.text(res.receive_phone); 			// 收件人电话
							obj.adressDetail.text(res.receive_address); 	// 收件人地址
							obj.orderNumBot.text(res.orderid); 				// 底部的订单编号
							obj.orderNum.text(res.orderid); 				// 订单详情处的订单编号
							createOrder(res.detail); 						// 订单详情,可能有多个-->数组
							obj.orderState.text(res.order_state); 			// 订单的状态
							obj.createTime.text(res.order_create_time); 	// 订单的创建时间
							obj.numBot.text(res.count); 					// 订单详情底部的商品数量
							// 显示订单详情底部的订单总价格
							if (res.order_pay_price != '0.00' && res.order_pay_integral != '0') { // 集分兑换商城集分加现金商品
								obj.price.text(res.order_pay_price + '元+' + res.order_pay_integral + '集分');
							} else if (res.order_pay_price == '0.00' && res.order_pay_integral != '0') { // 集分兑换商城纯集分商品
								obj.price.text(res.order_pay_integral + '集分');
							} else if (res.order_pay_price != '0.00' && res.order_pay_integral == '0') { // 集分商城纯现金商品
								obj.price.text(res.order_pay_price + '元');
							}
							// 根据订单状态判断是否显示订单支付的时间
							if (res.order_state == '待付款' || res.order_state == '取消订单') {
								obj.payTime.parent('p').hide();
							} else {
								obj.payTime.text(res.order_pay_time);
							}
							// 根据订单状态判断是否显示订单发货的时间
							if (res.order_state == '待付款' || res.order_state == '待发货' || res.order_state == '取消订单') {
								obj.deliverTime.parent('p').hide();
							} else {
								obj.deliverTime.text(res.delivery_time);
							}
						}
					},
					error: function (err) {
						console.log(err);
					}
				});
			} else if (orderid.substring(0, 1) == 'Z') {
				$.ajax({
					type: 'post',
					url: 'http://a.91jfk.com/Product/Order/order_detail',
					dataType: 'json',
					data: {
						orderid: orderid
					},
					success: function (res) {
						console.log(res);
						switch (res.order_state) {
							case '1':
								obj.orderStateTop.text('待付款'); 	// 顶部的订单状态
								obj.orderState.text('待付款'); 	// 订单详情处的订单状态
								break;
							case '2':
								obj.orderStateTop.text('待发货'); 	// 顶部的订单状态
								obj.orderState.text('待发货'); 	// 订单详情处的订单状态
								break;
							case '3':
								obj.orderStateTop.text('待收货'); 	// 顶部的订单状态
								obj.orderState.text('待收货'); 	// 订单详情处的订单状态
								break;
							case '4':
								obj.orderStateTop.text('已签收'); 	// 顶部的订单状态
								obj.orderState.text('已签收'); 	// 订单详情处的订单状态
								break;
							case '5':
								obj.orderStateTop.text('取消订单'); // 顶部的订单状态
								obj.orderState.text('取消订单'); 	// 订单详情处的订单状态
								break;
							case '6':
								obj.orderStateTop.text('退换货'); 	// 顶部的订单状态
								obj.orderState.text('退换货'); 	// 订单详情处的订单状态
								break;
							default:break;
						}
						// 根据订单的状态值判断是否显示物流栏
						if (res.order_state == '3' || res.order_state == '4') {
							obj.logistic.click(function(){
								var cpy = res.logistics_company;   // 物流公司
								var num = res.logistics_number;    // 物流单号
								var callbackUrl = window.location.href;
								window.location.href = "http://a.91jfk.com/HomePublic/Common/search_express?type=" + cpy + "&postid=" + num + "&callbackurl=" + callbackUrl;
							});
						} else {
							obj.logistic.hide();
						}
						obj.receiptPerson.text(res.name); 		// 收件人姓名
						obj.telephone.text(res.tel); 			// 收件人电话
						obj.adressDetail.text(res.address); 	// 收件人地址
						obj.orderNumBot.text(res.orderid); 		// 底部的订单编号
						obj.orderNum.text(res.orderid); 		// 订单详情处的订单编号
						loadZeroOrder(res.list); 				// 订单详情,可能有多个-->数组
						var changeTime = new transformTime();
						obj.createTime.text(changeTime.transform('Y-m-d H:i:s',res.order_create_time)); // 订单的创建时间
						obj.numBot.text(res.list.length); 		// 订单详情底部的商品数量
						// 显示订单详情底部的订单总价格
						obj.price.text(res.total + '元');
						// 根据订单状态判断是否显示订单支付的时间 未付款状态不显示付款时间
						if (res.order_state == '1' || res.order_state == '5') {
							obj.payTime.parent('p').hide();
						} else {
							obj.payTime.text(changeTime.transform('Y-m-d H:i:s',res.pay_time));
						}
						// 根据订单状态判断是否显示订单发货的时间 未付款、取消订单状态不显示发货时间
						if (res.order_state == '1' || res.order_state == '2' || res.order_state == '5') {
							obj.deliverTime.parent('p').hide();
						} else {
							obj.deliverTime.text(changeTime.transform('Y-m-d H:i:s',res.delivery_time));
						}
					},
					error: function (err) {
						console.log(err);
					}
				});
			}
		}
		// 集分商城和集分兑换商城循环加载订单
		function createOrder(arr) {
			var detailConBox = $('.detailConBox');
			for (var i = 0; i < arr.length; i++) {
				if (arr[i].cash_total_price == '0.00' && arr[i].point_total_price != '0') { // 集分兑换商城纯集分商品
					var orderDeatailCon = $(
						'<div class="orderDetail_con"><div class="orderDetail_con_lt"><div class="lt_imgBox"><img src="' + arr[i].show_pic +
						'" alt="" /></div></div><div class="orderDetail_con_rt"><p class="p_top"><span>' + arr[i].pname +
						'</span><span class="red">￥' + arr[i].point_total_price + '集分' + '</span></p><p class="p_bot"><span>' + arr[i]
						.shuxing_zhi.replace(/'/g,'') + '</span><span class="red">x' + arr[i].purchase_num + '</span></p></div></div>');
					detailConBox.append(orderDeatailCon);
				} else if (arr[i].cash_total_price != '0.00' && arr[i].point_total_price == '0') { // 集分商城纯现金商品
					var orderDeatailCon = $(
						'<div class="orderDetail_con"><div class="orderDetail_con_lt"><div class="lt_imgBox"><img src="' + arr[i].show_pic +
						'" alt="" /></div></div><div class="orderDetail_con_rt"><p class="p_top"><span>' + arr[i].pname +
						'</span><span class="red">￥' + arr[i].cash_total_price + '元' + '</span></p><p class="p_bot"><span>' + arr[i].shuxing_zhi.replace(/'/g,'') +
						'</span><span class="red">x' + arr[i].purchase_num + '</span></p></div></div>');
					detailConBox.append(orderDeatailCon);
				} else if (arr[i].cash_total_price != '0.00' && arr[i].point_total_price != '0') { // 集分兑换商城集分加现金商品
					var orderDeatailCon = $(
						'<div class="orderDetail_con"><div class="orderDetail_con_lt"><div class="lt_imgBox"><img src="' + arr[i].show_pic +
						'" alt="" /></div></div><div class="orderDetail_con_rt"><p class="p_top"><span>' + arr[i].pname +
						'</span><span class="red">￥' + arr[i].cash_total_price + '元+' + arr[i].point_total_price + '集分' +
						'</span></p><p class="p_bot"><span>' + arr[i].shuxing_zhi.replace(/'/g,'') + '</span><span class="red">x' + arr[i].purchase_num +
						'</span></p></div></div>');
					detailConBox.append(orderDeatailCon);
				}
			}
		}
		// 零元购商城循环加载订单
		function loadZeroOrder(arr) {
			var detailConBox = $('.detailConBox');
			for (var i = 0; i < arr.length; i++) {
				var orderDeatailCon = $(
					'<div class="orderDetail_con"><div class="orderDetail_con_lt"><div class="lt_imgBox"><img src="' + arr[i].thumbnail +
					'" alt="" /></div></div><div class="orderDetail_con_rt"><p class="p_top"><span>' + arr[i].title +
					'</span><span class="red">￥' + arr[i].price + '元' + '</span></p><p class="p_bot"><span class="red">x' + arr[i].num +
					'</span></p></div></div>');
				detailConBox.append(orderDeatailCon);
			}
		}
	});
</script>